<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: ActiveSupport::Multibyte::Handlers::UTF8Handler</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">ActiveSupport::Multibyte::Handlers::UTF8Handler</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../../files/vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler_rb.html">
                vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../../../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
<a href="UTF8Handler.html">UTF8Handler</a> implements Unicode aware
operations for strings, these operations will be used by the <a
href="../Chars.html">Chars</a> proxy when $KCODE is set to
&#8216;UTF8&#8217;.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000517">[]=</a>&nbsp;&nbsp;
      <a href="#M000529">capitalize</a>&nbsp;&nbsp;
      <a href="#M000520">center</a>&nbsp;&nbsp;
      <a href="#M000532">compose</a>&nbsp;&nbsp;
      <a href="#M000546">compose_codepoints</a>&nbsp;&nbsp;
      <a href="#M000534">consumes?</a>&nbsp;&nbsp;
      <a href="#M000531">decompose</a>&nbsp;&nbsp;
      <a href="#M000545">decompose_codepoints</a>&nbsp;&nbsp;
      <a href="#M000528">downcase</a>&nbsp;&nbsp;
      <a href="#M000535">g_length</a>&nbsp;&nbsp;
      <a href="#M000540">g_pack</a>&nbsp;&nbsp;
      <a href="#M000539">g_unpack</a>&nbsp;&nbsp;
      <a href="#M000537">in_char_class?</a>&nbsp;&nbsp;
      <a href="#M000516">index</a>&nbsp;&nbsp;
      <a href="#M000515">insert</a>&nbsp;&nbsp;
      <a href="#M000541">justify</a>&nbsp;&nbsp;
      <a href="#M000519">ljust</a>&nbsp;&nbsp;
      <a href="#M000522">lstrip</a>&nbsp;&nbsp;
      <a href="#M000530">normalize</a>&nbsp;&nbsp;
      <a href="#M000542">padding</a>&nbsp;&nbsp;
      <a href="#M000544">reorder_characters</a>&nbsp;&nbsp;
      <a href="#M000525">reverse</a>&nbsp;&nbsp;
      <a href="#M000518">rjust</a>&nbsp;&nbsp;
      <a href="#M000521">rstrip</a>&nbsp;&nbsp;
      <a href="#M000524">size</a>&nbsp;&nbsp;
      <a href="#M000526">slice</a>&nbsp;&nbsp;
      <a href="#M000523">strip</a>&nbsp;&nbsp;
      <a href="#M000536">tidy_bytes</a>&nbsp;&nbsp;
      <a href="#M000543">to_case</a>&nbsp;&nbsp;
      <a href="#M000533">translate_offset</a>&nbsp;&nbsp;
      <a href="#M000538">u_unpack</a>&nbsp;&nbsp;
      <a href="#M000527">upcase</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">HANGUL_SBASE</td>
          <td>=</td>
          <td class="context-item-value">0xAC00</td>
          <td width="3em">&nbsp;</td>
          <td class="context-item-desc">
Hangul character boundaries and properties

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">HANGUL_LBASE</td>
          <td>=</td>
          <td class="context-item-value">0x1100</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">HANGUL_VBASE</td>
          <td>=</td>
          <td class="context-item-value">0x1161</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">HANGUL_TBASE</td>
          <td>=</td>
          <td class="context-item-value">0x11A7</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">HANGUL_LCOUNT</td>
          <td>=</td>
          <td class="context-item-value">19</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">HANGUL_VCOUNT</td>
          <td>=</td>
          <td class="context-item-value">21</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">HANGUL_TCOUNT</td>
          <td>=</td>
          <td class="context-item-value">28</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">HANGUL_NCOUNT</td>
          <td>=</td>
          <td class="context-item-value">HANGUL_VCOUNT * HANGUL_TCOUNT</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">HANGUL_SCOUNT</td>
          <td>=</td>
          <td class="context-item-value">11172</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">HANGUL_SLAST</td>
          <td>=</td>
          <td class="context-item-value">HANGUL_SBASE + HANGUL_SCOUNT</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">HANGUL_JAMO_FIRST</td>
          <td>=</td>
          <td class="context-item-value">0x1100</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">HANGUL_JAMO_LAST</td>
          <td>=</td>
          <td class="context-item-value">0x11FF</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">UNICODE_WHITESPACE</td>
          <td>=</td>
          <td class="context-item-value">[       (0x0009..0x000D).to_a,  # White_Space # Cc   [5] &lt;control-0009&gt;..&lt;control-000D&gt;       0x0020,          # White_Space # Zs       SPACE       0x0085,          # White_Space # Cc       &lt;control-0085&gt;       0x00A0,          # White_Space # Zs       NO-BREAK SPACE       0x1680,          # White_Space # Zs       OGHAM SPACE MARK       0x180E,          # White_Space # Zs       MONGOLIAN VOWEL SEPARATOR       (0x2000..0x200A).to_a, # White_Space # Zs  [11] EN QUAD..HAIR SPACE       0x2028,          # White_Space # Zl       LINE SEPARATOR       0x2029,          # White_Space # Zp       PARAGRAPH SEPARATOR       0x202F,          # White_Space # Zs       NARROW NO-BREAK SPACE       0x205F,          # White_Space # Zs       MEDIUM MATHEMATICAL SPACE       0x3000,          # White_Space # Zs       IDEOGRAPHIC SPACE     ].flatten.freeze</td>
          <td width="3em">&nbsp;</td>
          <td class="context-item-desc">
All the unicode whitespace

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">UNICODE_LEADERS_AND_TRAILERS</td>
          <td>=</td>
          <td class="context-item-value">UNICODE_WHITESPACE + [65279]</td>
          <td width="3em">&nbsp;</td>
          <td class="context-item-desc">
BOM (byte order mark) can also be seen as whitespace, it&#8216;s a
non-rendering character used to distinguish between little and big endian.
This is not an issue in utf-8, so it must be ignored.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">UTF8_PAT</td>
          <td>=</td>
          <td class="context-item-value">/\A(?:                    [\x00-\x7f]                                     |                    [\xc2-\xdf] [\x80-\xbf]                         |                    \xe0        [\xa0-\xbf] [\x80-\xbf]             |                    [\xe1-\xef] [\x80-\xbf] [\x80-\xbf]             |                    \xf0        [\x90-\xbf] [\x80-\xbf] [\x80-\xbf] |                    [\xf1-\xf3] [\x80-\xbf] [\x80-\xbf] [\x80-\xbf] |                    \xf4        [\x80-\x8f] [\x80-\xbf] [\x80-\xbf]                   )*\z/xn</td>
          <td width="3em">&nbsp;</td>
          <td class="context-item-desc">
Borrowed from the Kconv library by Shinji KONO - (also as seen on the W3C
site)

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">UNICODE_TRAILERS_PAT</td>
          <td>=</td>
          <td class="context-item-value">/(#{codepoints_to_pattern(UNICODE_LEADERS_AND_TRAILERS)})+\Z/</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">UNICODE_LEADERS_PAT</td>
          <td>=</td>
          <td class="context-item-value">/\A(#{codepoints_to_pattern(UNICODE_LEADERS_AND_TRAILERS)})+/</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">UCD</td>
          <td>=</td>
          <td class="context-item-value">UnicodeDatabase.new</td>
          <td width="3em">&nbsp;</td>
          <td class="context-item-desc">
UniCode Database

</td>
        </tr>
        </table>
      </div>
    </div>

    <div id="aliases-list">
      <h3 class="section-bar">External Aliases</h3>

      <div class="name-list">
                        <table summary="aliases">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">size</td>
          <td>-&gt;</td>
          <td class="context-item-value">length</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">slice</td>
          <td>-&gt;</td>
          <td class="context-item-value">[]</td>
        </tr>
                        </table>
      </div>
    </div>


      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000517" class="method-detail">
        <a name="M000517"></a>

        <div class="method-heading">
          <a href="#M000517" class="method-signature">
          <span class="method-name">[]=</span><span class="method-args">(str, *args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Works just like the indexed replace method on string, except instead of
byte offsets you specify character offsets.
</p>
<p>
Example:
</p>
<pre>
  s = &quot;Müller&quot;
  s.chars[2] = &quot;e&quot; # Replace character with offset 2
  s
  #=&gt; &quot;Müeler&quot;

  s = &quot;Müller&quot;
  s.chars[1, 2] = &quot;ö&quot; # Replace 2 characters at character offset 1
  s
  #=&gt; &quot;Möler&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000517-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000517-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 158</span>
158:       <span class="ruby-keyword kw">def</span> <span class="ruby-operator">[]=</span>(<span class="ruby-identifier">str</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
159:         <span class="ruby-identifier">replace_by</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">pop</span>
160:         <span class="ruby-comment cmt"># Indexed replace with regular expressions already works</span>
161:         <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">str</span>[<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>] = <span class="ruby-identifier">replace_by</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Regexp</span>)
162:         <span class="ruby-identifier">result</span> = <span class="ruby-identifier">u_unpack</span>(<span class="ruby-identifier">str</span>)
163:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Fixnum</span>)
164:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">IndexError</span>, <span class="ruby-node">&quot;index #{args[0]} out of string&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">&gt;=</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">length</span>
165:           <span class="ruby-identifier">min</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">0</span>]
166:           <span class="ruby-identifier">max</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">nil?</span> <span class="ruby-value">? </span><span class="ruby-identifier">min</span> <span class="ruby-operator">:</span> (<span class="ruby-identifier">min</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">-</span> <span class="ruby-value">1</span>)
167:           <span class="ruby-identifier">range</span> = <span class="ruby-constant">Range</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">min</span>, <span class="ruby-identifier">max</span>)
168:           <span class="ruby-identifier">replace_by</span> = [<span class="ruby-identifier">replace_by</span>].<span class="ruby-identifier">pack</span>(<span class="ruby-value str">'U'</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">replace_by</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Fixnum</span>)
169:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Range</span>)
170:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">RangeError</span>, <span class="ruby-node">&quot;#{args[0]} out of range&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">min</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">length</span>
171:           <span class="ruby-identifier">range</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">0</span>]
172:         <span class="ruby-keyword kw">else</span>
173:           <span class="ruby-identifier">needle</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">to_s</span>
174:           <span class="ruby-identifier">min</span> = <span class="ruby-identifier">index</span>(<span class="ruby-identifier">str</span>, <span class="ruby-identifier">needle</span>)
175:           <span class="ruby-identifier">max</span> = <span class="ruby-identifier">min</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">length</span>(<span class="ruby-identifier">needle</span>) <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
176:           <span class="ruby-identifier">range</span> = <span class="ruby-constant">Range</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">min</span>, <span class="ruby-identifier">max</span>)
177:         <span class="ruby-keyword kw">end</span>
178:         <span class="ruby-identifier">result</span>[<span class="ruby-identifier">range</span>] = <span class="ruby-identifier">u_unpack</span>(<span class="ruby-identifier">replace_by</span>)
179:         <span class="ruby-identifier">str</span>.<span class="ruby-identifier">replace</span>(<span class="ruby-identifier">result</span>.<span class="ruby-identifier">pack</span>(<span class="ruby-value str">'U*'</span>))
180:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000529" class="method-detail">
        <a name="M000529"></a>

        <div class="method-heading">
          <a href="#M000529" class="method-signature">
          <span class="method-name">capitalize</span><span class="method-args">(str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a copy of <tt>str</tt> with the first character converted to
uppercase and the remainder to lowercase
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000529-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000529-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 276</span>
276:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">capitalize</span>(<span class="ruby-identifier">str</span>)
277:         <span class="ruby-identifier">upcase</span>(<span class="ruby-identifier">slice</span>(<span class="ruby-identifier">str</span>, <span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">0</span>)) <span class="ruby-operator">+</span> <span class="ruby-identifier">downcase</span>(<span class="ruby-identifier">slice</span>(<span class="ruby-identifier">str</span>, <span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>) <span class="ruby-operator">||</span> <span class="ruby-value str">''</span>)
278:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000520" class="method-detail">
        <a name="M000520"></a>

        <div class="method-heading">
          <a href="#M000520" class="method-signature">
          <span class="method-name">center</span><span class="method-args">(str, integer, padstr=' ')</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Works just like String#center, only integer specifies characters instead of
bytes.
</p>
<p>
Example:
</p>
<pre>
  &quot;¾ cup&quot;.chars.center(8).to_s
  #=&gt; &quot; ¾ cup  &quot;

  &quot;¾ cup&quot;.chars.center(8, &quot; &quot;).to_s # Use non-breaking whitespace
  #=&gt; &quot; ¾ cup  &quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000520-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000520-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 217</span>
217:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">center</span>(<span class="ruby-identifier">str</span>, <span class="ruby-identifier">integer</span>, <span class="ruby-identifier">padstr</span>=<span class="ruby-value str">' '</span>)
218:         <span class="ruby-identifier">justify</span>(<span class="ruby-identifier">str</span>, <span class="ruby-identifier">integer</span>, <span class="ruby-identifier">:center</span>, <span class="ruby-identifier">padstr</span>)
219:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000532" class="method-detail">
        <a name="M000532"></a>

        <div class="method-heading">
          <a href="#M000532" class="method-signature">
          <span class="method-name">compose</span><span class="method-args">(str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Perform composition on the characters in the string
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000532-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000532-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 312</span>
312:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">compose</span>(<span class="ruby-identifier">str</span>)
313:         <span class="ruby-identifier">compose_codepoints</span> <span class="ruby-identifier">u_unpack</span>(<span class="ruby-identifier">str</span>).<span class="ruby-identifier">pack</span>(<span class="ruby-value str">'U*'</span>)
314:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000534" class="method-detail">
        <a name="M000534"></a>

        <div class="method-heading">
          <a href="#M000534" class="method-signature">
          <span class="method-name">consumes?</span><span class="method-args">(str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Checks if the string is valid UTF8.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000534-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000534-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 342</span>
342:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">consumes?</span>(<span class="ruby-identifier">str</span>)
343:         <span class="ruby-comment cmt"># Unpack is a little bit faster than regular expressions</span>
344:         <span class="ruby-keyword kw">begin</span>
345:           <span class="ruby-identifier">str</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-value str">'U*'</span>)
346:           <span class="ruby-keyword kw">true</span>
347:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ArgumentError</span>
348:           <span class="ruby-keyword kw">false</span>
349:         <span class="ruby-keyword kw">end</span>
350:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000531" class="method-detail">
        <a name="M000531"></a>

        <div class="method-heading">
          <a href="#M000531" class="method-signature">
          <span class="method-name">decompose</span><span class="method-args">(str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Perform decomposition on the characters in the string
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000531-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000531-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 307</span>
307:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decompose</span>(<span class="ruby-identifier">str</span>)
308:         <span class="ruby-identifier">decompose_codepoints</span>(<span class="ruby-identifier">:canonical</span>, <span class="ruby-identifier">u_unpack</span>(<span class="ruby-identifier">str</span>)).<span class="ruby-identifier">pack</span>(<span class="ruby-value str">'U*'</span>)
309:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000528" class="method-detail">
        <a name="M000528"></a>

        <div class="method-heading">
          <a href="#M000528" class="method-signature">
          <span class="method-name">downcase</span><span class="method-args">(str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Convert characters in the string to lowercase
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000528-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000528-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 273</span>
273:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">downcase</span>(<span class="ruby-identifier">str</span>); <span class="ruby-identifier">to_case</span> <span class="ruby-identifier">:lowercase_mapping</span>, <span class="ruby-identifier">str</span>; <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000535" class="method-detail">
        <a name="M000535"></a>

        <div class="method-heading">
          <a href="#M000535" class="method-signature">
          <span class="method-name">g_length</span><span class="method-args">(str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the number of grapheme clusters in the string. This method is very
likely to be moved or renamed in future versions.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000535-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000535-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 354</span>
354:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">g_length</span>(<span class="ruby-identifier">str</span>)
355:         <span class="ruby-identifier">g_unpack</span>(<span class="ruby-identifier">str</span>).<span class="ruby-identifier">length</span>
356:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000516" class="method-detail">
        <a name="M000516"></a>

        <div class="method-heading">
          <a href="#M000516" class="method-signature">
          <span class="method-name">index</span><span class="method-args">(str, *args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the position of the passed argument in the string, counting in
codepoints
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000516-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000516-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 139</span>
139:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">index</span>(<span class="ruby-identifier">str</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
140:         <span class="ruby-identifier">bidx</span> = <span class="ruby-identifier">str</span>.<span class="ruby-identifier">index</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
141:         <span class="ruby-identifier">bidx</span> <span class="ruby-value">? </span>(<span class="ruby-identifier">u_unpack</span>(<span class="ruby-identifier">str</span>.<span class="ruby-identifier">slice</span>(<span class="ruby-value">0</span><span class="ruby-operator">...</span><span class="ruby-identifier">bidx</span>)).<span class="ruby-identifier">size</span>) <span class="ruby-operator">:</span> <span class="ruby-keyword kw">nil</span>
142:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000515" class="method-detail">
        <a name="M000515"></a>

        <div class="method-heading">
          <a href="#M000515" class="method-signature">
          <span class="method-name">insert</span><span class="method-args">(str, offset, fragment)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Inserts the passed string at specified codepoint offsets
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000515-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000515-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 129</span>
129:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">insert</span>(<span class="ruby-identifier">str</span>, <span class="ruby-identifier">offset</span>, <span class="ruby-identifier">fragment</span>)
130:         <span class="ruby-identifier">str</span>.<span class="ruby-identifier">replace</span>(
131:           <span class="ruby-identifier">u_unpack</span>(<span class="ruby-identifier">str</span>).<span class="ruby-identifier">insert</span>(
132:             <span class="ruby-identifier">offset</span>,
133:             <span class="ruby-identifier">u_unpack</span>(<span class="ruby-identifier">fragment</span>)
134:           ).<span class="ruby-identifier">flatten</span>.<span class="ruby-identifier">pack</span>(<span class="ruby-value str">'U*'</span>)
135:         )
136:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000519" class="method-detail">
        <a name="M000519"></a>

        <div class="method-heading">
          <a href="#M000519" class="method-signature">
          <span class="method-name">ljust</span><span class="method-args">(str, integer, padstr=' ')</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Works just like String#ljust, only integer specifies characters instead of
bytes.
</p>
<p>
Example:
</p>
<pre>
  &quot;¾ cup&quot;.chars.rjust(8).to_s
  #=&gt; &quot;¾ cup   &quot;

  &quot;¾ cup&quot;.chars.rjust(8, &quot; &quot;).to_s # Use non-breaking whitespace
  #=&gt; &quot;¾ cup   &quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000519-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000519-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 204</span>
204:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ljust</span>(<span class="ruby-identifier">str</span>, <span class="ruby-identifier">integer</span>, <span class="ruby-identifier">padstr</span>=<span class="ruby-value str">' '</span>)
205:         <span class="ruby-identifier">justify</span>(<span class="ruby-identifier">str</span>, <span class="ruby-identifier">integer</span>, <span class="ruby-identifier">:left</span>, <span class="ruby-identifier">padstr</span>)
206:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000522" class="method-detail">
        <a name="M000522"></a>

        <div class="method-heading">
          <a href="#M000522" class="method-signature">
          <span class="method-name">lstrip</span><span class="method-args">(str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Does Unicode-aware <a href="UTF8Handler.html#M000522">lstrip</a>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000522-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000522-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 227</span>
227:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">lstrip</span>(<span class="ruby-identifier">str</span>)
228:         <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-constant">UNICODE_LEADERS_PAT</span>, <span class="ruby-value str">''</span>)
229:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000530" class="method-detail">
        <a name="M000530"></a>

        <div class="method-heading">
          <a href="#M000530" class="method-signature">
          <span class="method-name">normalize</span><span class="method-args">(str, form=ActiveSupport::Multibyte::DEFAULT_NORMALIZATION_FORM)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the KC normalization of the string by default. NFKC is considered
the best normalization form for passing strings to databases and
validations.
</p>
<ul>
<li><tt>str</tt> - The string to perform normalization on.

</li>
<li><tt>form</tt> - The form you want to <a
href="UTF8Handler.html#M000530">normalize</a> in. Should be one of the
following: :c, :kc, :d or :kd.

</li>
</ul>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000530-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000530-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 289</span>
289:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">normalize</span>(<span class="ruby-identifier">str</span>, <span class="ruby-identifier">form</span>=<span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Multibyte</span><span class="ruby-operator">::</span><span class="ruby-constant">DEFAULT_NORMALIZATION_FORM</span>)
290:         <span class="ruby-comment cmt"># See http://www.unicode.org/reports/tr15, Table 1</span>
291:         <span class="ruby-identifier">codepoints</span> = <span class="ruby-identifier">u_unpack</span>(<span class="ruby-identifier">str</span>)
292:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">form</span>
293:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:d</span>
294:             <span class="ruby-identifier">reorder_characters</span>(<span class="ruby-identifier">decompose_codepoints</span>(<span class="ruby-identifier">:canonical</span>, <span class="ruby-identifier">codepoints</span>))
295:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:c</span>
296:             <span class="ruby-identifier">compose_codepoints</span> <span class="ruby-identifier">reorder_characters</span>(<span class="ruby-identifier">decompose_codepoints</span>(<span class="ruby-identifier">:canonical</span>, <span class="ruby-identifier">codepoints</span>))
297:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:kd</span>
298:             <span class="ruby-identifier">reorder_characters</span>(<span class="ruby-identifier">decompose_codepoints</span>(<span class="ruby-identifier">:compatability</span>, <span class="ruby-identifier">codepoints</span>))
299:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:kc</span>
300:             <span class="ruby-identifier">compose_codepoints</span> <span class="ruby-identifier">reorder_characters</span>(<span class="ruby-identifier">decompose_codepoints</span>(<span class="ruby-identifier">:compatability</span>, <span class="ruby-identifier">codepoints</span>))
301:           <span class="ruby-keyword kw">else</span>
302:             <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;#{form} is not a valid normalization variant&quot;</span>, <span class="ruby-identifier">caller</span>
303:         <span class="ruby-keyword kw">end</span>.<span class="ruby-identifier">pack</span>(<span class="ruby-value str">'U*'</span>)
304:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000525" class="method-detail">
        <a name="M000525"></a>

        <div class="method-heading">
          <a href="#M000525" class="method-signature">
          <span class="method-name">reverse</span><span class="method-args">(str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Reverses codepoints in the string.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000525-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000525-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 243</span>
243:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reverse</span>(<span class="ruby-identifier">str</span>)
244:         <span class="ruby-identifier">u_unpack</span>(<span class="ruby-identifier">str</span>).<span class="ruby-identifier">reverse</span>.<span class="ruby-identifier">pack</span>(<span class="ruby-value str">'U*'</span>)
245:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000518" class="method-detail">
        <a name="M000518"></a>

        <div class="method-heading">
          <a href="#M000518" class="method-signature">
          <span class="method-name">rjust</span><span class="method-args">(str, integer, padstr=' ')</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Works just like String#rjust, only integer specifies characters instead of
bytes.
</p>
<p>
Example:
</p>
<pre>
  &quot;¾ cup&quot;.chars.rjust(8).to_s
  #=&gt; &quot;   ¾ cup&quot;

  &quot;¾ cup&quot;.chars.rjust(8, &quot; &quot;).to_s # Use non-breaking whitespace
  #=&gt; &quot;   ¾ cup&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000518-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000518-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 191</span>
191:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rjust</span>(<span class="ruby-identifier">str</span>, <span class="ruby-identifier">integer</span>, <span class="ruby-identifier">padstr</span>=<span class="ruby-value str">' '</span>)
192:         <span class="ruby-identifier">justify</span>(<span class="ruby-identifier">str</span>, <span class="ruby-identifier">integer</span>, <span class="ruby-identifier">:right</span>, <span class="ruby-identifier">padstr</span>)
193:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000521" class="method-detail">
        <a name="M000521"></a>

        <div class="method-heading">
          <a href="#M000521" class="method-signature">
          <span class="method-name">rstrip</span><span class="method-args">(str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Does Unicode-aware <a href="UTF8Handler.html#M000521">rstrip</a>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000521-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000521-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 222</span>
222:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rstrip</span>(<span class="ruby-identifier">str</span>)
223:         <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-constant">UNICODE_TRAILERS_PAT</span>, <span class="ruby-value str">''</span>)
224:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000524" class="method-detail">
        <a name="M000524"></a>

        <div class="method-heading">
          <a href="#M000524" class="method-signature">
          <span class="method-name">size</span><span class="method-args">(str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the number of codepoints in the string
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000524-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000524-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 237</span>
237:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">size</span>(<span class="ruby-identifier">str</span>)
238:         <span class="ruby-identifier">u_unpack</span>(<span class="ruby-identifier">str</span>).<span class="ruby-identifier">size</span>
239:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000526" class="method-detail">
        <a name="M000526"></a>

        <div class="method-heading">
          <a href="#M000526" class="method-signature">
          <span class="method-name">slice</span><span class="method-args">(str, *args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Implements Unicode-aware <a href="UTF8Handler.html#M000526">slice</a> with
codepoints. Slicing on one point returns the codepoints for that character.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000526-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000526-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 249</span>
249:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">slice</span>(<span class="ruby-identifier">str</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
250:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">2</span>
251:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;wrong number of arguments (#{args.size} for 1)&quot;</span> <span class="ruby-comment cmt"># Do as if we were native</span>
252:         <span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">2</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span>(<span class="ruby-identifier">args</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Numeric</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Regexp</span>)))
253:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-node">&quot;cannot convert #{args.first.class} into Integer&quot;</span> <span class="ruby-comment cmt"># Do as if we were native</span>
254:         <span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">2</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">args</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Numeric</span>))
255:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-node">&quot;cannot convert #{args[1].class} into Integer&quot;</span> <span class="ruby-comment cmt"># Do as if we were native</span>
256:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Range</span>
257:           <span class="ruby-identifier">cps</span> = <span class="ruby-identifier">u_unpack</span>(<span class="ruby-identifier">str</span>).<span class="ruby-identifier">slice</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
258:           <span class="ruby-identifier">cps</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">nil</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">cps</span>.<span class="ruby-identifier">pack</span>(<span class="ruby-value str">'U*'</span>)
259:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Regexp</span>
260:           <span class="ruby-identifier">str</span>.<span class="ruby-identifier">slice</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
261:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Numeric</span>)
262:           <span class="ruby-identifier">u_unpack</span>(<span class="ruby-identifier">str</span>)[<span class="ruby-identifier">args</span>[<span class="ruby-value">0</span>]]
263:         <span class="ruby-keyword kw">else</span>
264:           <span class="ruby-identifier">u_unpack</span>(<span class="ruby-identifier">str</span>).<span class="ruby-identifier">slice</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>).<span class="ruby-identifier">pack</span>(<span class="ruby-value str">'U*'</span>)
265:         <span class="ruby-keyword kw">end</span>
266:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000523" class="method-detail">
        <a name="M000523"></a>

        <div class="method-heading">
          <a href="#M000523" class="method-signature">
          <span class="method-name">strip</span><span class="method-args">(str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Removed leading and trailing whitespace
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000523-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000523-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 232</span>
232:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">strip</span>(<span class="ruby-identifier">str</span>)
233:         <span class="ruby-identifier">str</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-constant">UNICODE_LEADERS_PAT</span>, <span class="ruby-value str">''</span>).<span class="ruby-identifier">gsub</span>(<span class="ruby-constant">UNICODE_TRAILERS_PAT</span>, <span class="ruby-value str">''</span>)
234:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000536" class="method-detail">
        <a name="M000536"></a>

        <div class="method-heading">
          <a href="#M000536" class="method-signature">
          <span class="method-name">tidy_bytes</span><span class="method-args">(str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Replaces all the non-utf-8 bytes by their iso-8859-1 or cp1252 equivalent
resulting in a valid utf-8 string
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000536-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000536-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 359</span>
359:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">tidy_bytes</span>(<span class="ruby-identifier">str</span>)
360:         <span class="ruby-identifier">str</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp re">//</span><span class="ruby-identifier">u</span>).<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
361:           <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">UTF8_PAT</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">c</span>)
362:             <span class="ruby-identifier">n</span> = <span class="ruby-identifier">c</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-value str">'C'</span>)[<span class="ruby-value">0</span>]
363:             <span class="ruby-identifier">n</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">128</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">n</span>.<span class="ruby-identifier">chr</span> <span class="ruby-operator">:</span>
364:             <span class="ruby-identifier">n</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">160</span> <span class="ruby-operator">?</span> [<span class="ruby-constant">UCD</span>.<span class="ruby-identifier">cp1252</span>[<span class="ruby-identifier">n</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">n</span>].<span class="ruby-identifier">pack</span>(<span class="ruby-value str">'U'</span>) <span class="ruby-operator">:</span>
365:             <span class="ruby-identifier">n</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">192</span> <span class="ruby-operator">?</span> <span class="ruby-value str">&quot;\xC2&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">n</span>.<span class="ruby-identifier">chr</span> <span class="ruby-operator">:</span> <span class="ruby-value str">&quot;\xC3&quot;</span> <span class="ruby-operator">+</span> (<span class="ruby-identifier">n</span><span class="ruby-operator">-</span><span class="ruby-value">64</span>).<span class="ruby-identifier">chr</span>
366:           <span class="ruby-keyword kw">else</span>
367:             <span class="ruby-identifier">c</span>
368:           <span class="ruby-keyword kw">end</span>
369:         <span class="ruby-keyword kw">end</span>.<span class="ruby-identifier">join</span>
370:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000533" class="method-detail">
        <a name="M000533"></a>

        <div class="method-heading">
          <a href="#M000533" class="method-signature">
          <span class="method-name">translate_offset</span><span class="method-args">(str, byte_offset)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Used to translate an offset from bytes to characters, for instance one
received from a regular expression match
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000533-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000533-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 321</span>
321:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">translate_offset</span>(<span class="ruby-identifier">str</span>, <span class="ruby-identifier">byte_offset</span>)
322:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">byte_offset</span>.<span class="ruby-identifier">nil?</span>
323:         <span class="ruby-keyword kw">return</span> <span class="ruby-value">0</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">str</span> <span class="ruby-operator">==</span> <span class="ruby-value str">''</span>
324:         <span class="ruby-identifier">chunk</span> = <span class="ruby-identifier">str</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-identifier">byte_offset</span>]
325:         <span class="ruby-keyword kw">begin</span>
326:           <span class="ruby-keyword kw">begin</span>
327:             <span class="ruby-identifier">chunk</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-value str">'U*'</span>).<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
328:           <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ArgumentError</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
329:             <span class="ruby-identifier">chunk</span> = <span class="ruby-identifier">str</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span>(<span class="ruby-identifier">byte_offset</span><span class="ruby-operator">+=</span><span class="ruby-value">1</span>)]
330:             <span class="ruby-comment cmt"># Stop retrying at the end of the string</span>
331:             <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">byte_offset</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">chunk</span>.<span class="ruby-identifier">length</span> 
332:             <span class="ruby-comment cmt"># We damaged a character, retry</span>
333:             <span class="ruby-keyword kw">retry</span>
334:           <span class="ruby-keyword kw">end</span>
335:         <span class="ruby-comment cmt"># Catch the ArgumentError so we can throw our own</span>
336:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ArgumentError</span> 
337:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">EncodingError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">'malformed UTF-8 character'</span>)
338:         <span class="ruby-keyword kw">end</span>
339:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000527" class="method-detail">
        <a name="M000527"></a>

        <div class="method-heading">
          <a href="#M000527" class="method-signature">
          <span class="method-name">upcase</span><span class="method-args">(str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Convert characters in the string to uppercase
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000527-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000527-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 270</span>
270:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">upcase</span>(<span class="ruby-identifier">str</span>); <span class="ruby-identifier">to_case</span> <span class="ruby-identifier">:uppercase_mapping</span>, <span class="ruby-identifier">str</span>; <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Protected Class methods</h3>

      <div id="method-M000546" class="method-detail">
        <a name="M000546"></a>

        <div class="method-heading">
          <a href="#M000546" class="method-signature">
          <span class="method-name">compose_codepoints</span><span class="method-args">(codepoints)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Compose decomposed characters to the composed form
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000546-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000546-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 503</span>
503:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">compose_codepoints</span>(<span class="ruby-identifier">codepoints</span>)
504:         <span class="ruby-identifier">pos</span> = <span class="ruby-value">0</span>
505:         <span class="ruby-identifier">eoa</span> = <span class="ruby-identifier">codepoints</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
506:         <span class="ruby-identifier">starter_pos</span> = <span class="ruby-value">0</span>
507:         <span class="ruby-identifier">starter_char</span> = <span class="ruby-identifier">codepoints</span>[<span class="ruby-value">0</span>]
508:         <span class="ruby-identifier">previous_combining_class</span> = <span class="ruby-value">-1</span>
509:         <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">pos</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">eoa</span>
510:           <span class="ruby-identifier">pos</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
511:           <span class="ruby-identifier">lindex</span> = <span class="ruby-identifier">starter_char</span> <span class="ruby-operator">-</span> <span class="ruby-constant">HANGUL_LBASE</span>
512:           <span class="ruby-comment cmt"># -- Hangul</span>
513:           <span class="ruby-keyword kw">if</span> <span class="ruby-value">0</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-identifier">lindex</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">lindex</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">HANGUL_LCOUNT</span>
514:             <span class="ruby-identifier">vindex</span> = <span class="ruby-identifier">codepoints</span>[<span class="ruby-identifier">starter_pos</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>] <span class="ruby-operator">-</span> <span class="ruby-constant">HANGUL_VBASE</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-identifier">vindex</span> = <span class="ruby-value">-1</span>
515:             <span class="ruby-keyword kw">if</span> <span class="ruby-value">0</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-identifier">vindex</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">vindex</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">HANGUL_VCOUNT</span>
516:               <span class="ruby-identifier">tindex</span> = <span class="ruby-identifier">codepoints</span>[<span class="ruby-identifier">starter_pos</span><span class="ruby-operator">+</span><span class="ruby-value">2</span>] <span class="ruby-operator">-</span> <span class="ruby-constant">HANGUL_TBASE</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-identifier">tindex</span> = <span class="ruby-value">-1</span>
517:               <span class="ruby-keyword kw">if</span> <span class="ruby-value">0</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-identifier">tindex</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">tindex</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">HANGUL_TCOUNT</span>
518:                 <span class="ruby-identifier">j</span> = <span class="ruby-identifier">starter_pos</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span>
519:                 <span class="ruby-identifier">eoa</span> <span class="ruby-operator">-=</span> <span class="ruby-value">2</span>
520:               <span class="ruby-keyword kw">else</span>
521:                 <span class="ruby-identifier">tindex</span> = <span class="ruby-value">0</span>
522:                 <span class="ruby-identifier">j</span> = <span class="ruby-identifier">starter_pos</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
523:                 <span class="ruby-identifier">eoa</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
524:               <span class="ruby-keyword kw">end</span>
525:               <span class="ruby-identifier">codepoints</span>[<span class="ruby-identifier">starter_pos</span><span class="ruby-operator">..</span><span class="ruby-identifier">j</span>] = (<span class="ruby-identifier">lindex</span> <span class="ruby-operator">*</span> <span class="ruby-constant">HANGUL_VCOUNT</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">vindex</span>) <span class="ruby-operator">*</span> <span class="ruby-constant">HANGUL_TCOUNT</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">tindex</span> <span class="ruby-operator">+</span> <span class="ruby-constant">HANGUL_SBASE</span>
526:             <span class="ruby-keyword kw">end</span>
527:             <span class="ruby-identifier">starter_pos</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
528:             <span class="ruby-identifier">starter_char</span> = <span class="ruby-identifier">codepoints</span>[<span class="ruby-identifier">starter_pos</span>]
529:           <span class="ruby-comment cmt"># -- Other characters</span>
530:           <span class="ruby-keyword kw">else</span>
531:             <span class="ruby-identifier">current_char</span> = <span class="ruby-identifier">codepoints</span>[<span class="ruby-identifier">pos</span>]
532:             <span class="ruby-identifier">current</span> = <span class="ruby-constant">UCD</span>[<span class="ruby-identifier">current_char</span>]
533:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">current</span>.<span class="ruby-identifier">combining_class</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">previous_combining_class</span>
534:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">ref</span> = <span class="ruby-constant">UCD</span>.<span class="ruby-identifier">composition_map</span>[<span class="ruby-identifier">starter_char</span>]
535:                 <span class="ruby-identifier">composition</span> = <span class="ruby-identifier">ref</span>[<span class="ruby-identifier">current_char</span>]
536:               <span class="ruby-keyword kw">else</span>
537:                 <span class="ruby-identifier">composition</span> = <span class="ruby-keyword kw">nil</span>
538:               <span class="ruby-keyword kw">end</span>
539:               <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">composition</span>.<span class="ruby-identifier">nil?</span>
540:                 <span class="ruby-identifier">codepoints</span>[<span class="ruby-identifier">starter_pos</span>] = <span class="ruby-identifier">composition</span>
541:                 <span class="ruby-identifier">starter_char</span> = <span class="ruby-identifier">composition</span>
542:                 <span class="ruby-identifier">codepoints</span>.<span class="ruby-identifier">delete_at</span> <span class="ruby-identifier">pos</span>
543:                 <span class="ruby-identifier">eoa</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
544:                 <span class="ruby-identifier">pos</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
545:                 <span class="ruby-identifier">previous_combining_class</span> = <span class="ruby-value">-1</span>
546:               <span class="ruby-keyword kw">else</span>
547:                 <span class="ruby-identifier">previous_combining_class</span> = <span class="ruby-identifier">current</span>.<span class="ruby-identifier">combining_class</span>
548:               <span class="ruby-keyword kw">end</span>
549:             <span class="ruby-keyword kw">else</span>
550:               <span class="ruby-identifier">previous_combining_class</span> = <span class="ruby-identifier">current</span>.<span class="ruby-identifier">combining_class</span>
551:             <span class="ruby-keyword kw">end</span>
552:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">current</span>.<span class="ruby-identifier">combining_class</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
553:               <span class="ruby-identifier">starter_pos</span> = <span class="ruby-identifier">pos</span>
554:               <span class="ruby-identifier">starter_char</span> = <span class="ruby-identifier">codepoints</span>[<span class="ruby-identifier">pos</span>]
555:             <span class="ruby-keyword kw">end</span>
556:           <span class="ruby-keyword kw">end</span>
557:         <span class="ruby-keyword kw">end</span>
558:         <span class="ruby-identifier">codepoints</span>
559:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000545" class="method-detail">
        <a name="M000545"></a>

        <div class="method-heading">
          <a href="#M000545" class="method-signature">
          <span class="method-name">decompose_codepoints</span><span class="method-args">(type, codepoints)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Decompose composed characters to the decomposed form
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000545-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000545-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 482</span>
482:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decompose_codepoints</span>(<span class="ruby-identifier">type</span>, <span class="ruby-identifier">codepoints</span>)
483:         <span class="ruby-identifier">codepoints</span>.<span class="ruby-identifier">inject</span>([]) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">decomposed</span>, <span class="ruby-identifier">cp</span><span class="ruby-operator">|</span>
484:           <span class="ruby-comment cmt"># if it's a hangul syllable starter character</span>
485:           <span class="ruby-keyword kw">if</span> <span class="ruby-constant">HANGUL_SBASE</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-identifier">cp</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">cp</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">HANGUL_SLAST</span>
486:             <span class="ruby-identifier">sindex</span> = <span class="ruby-identifier">cp</span> <span class="ruby-operator">-</span> <span class="ruby-constant">HANGUL_SBASE</span>
487:             <span class="ruby-identifier">ncp</span> = [] <span class="ruby-comment cmt"># new codepoints</span>
488:             <span class="ruby-identifier">ncp</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">HANGUL_LBASE</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">sindex</span> <span class="ruby-operator">/</span> <span class="ruby-constant">HANGUL_NCOUNT</span>
489:             <span class="ruby-identifier">ncp</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">HANGUL_VBASE</span> <span class="ruby-operator">+</span> (<span class="ruby-identifier">sindex</span> <span class="ruby-operator">%</span> <span class="ruby-constant">HANGUL_NCOUNT</span>) <span class="ruby-operator">/</span> <span class="ruby-constant">HANGUL_TCOUNT</span>
490:             <span class="ruby-identifier">tindex</span> = <span class="ruby-identifier">sindex</span> <span class="ruby-operator">%</span> <span class="ruby-constant">HANGUL_TCOUNT</span>
491:             <span class="ruby-identifier">ncp</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-constant">HANGUL_TBASE</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">tindex</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">tindex</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
492:             <span class="ruby-identifier">decomposed</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">ncp</span>
493:           <span class="ruby-comment cmt"># if the codepoint is decomposable in with the current decomposition type</span>
494:           <span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">ncp</span> = <span class="ruby-constant">UCD</span>[<span class="ruby-identifier">cp</span>].<span class="ruby-identifier">decomp_mapping</span>) <span class="ruby-keyword kw">and</span> (<span class="ruby-operator">!</span><span class="ruby-constant">UCD</span>[<span class="ruby-identifier">cp</span>].<span class="ruby-identifier">decomp_type</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">type</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:compatability</span>)
495:             <span class="ruby-identifier">decomposed</span>.<span class="ruby-identifier">concat</span> <span class="ruby-identifier">decompose_codepoints</span>(<span class="ruby-identifier">type</span>, <span class="ruby-identifier">ncp</span>.<span class="ruby-identifier">dup</span>)
496:           <span class="ruby-keyword kw">else</span>
497:             <span class="ruby-identifier">decomposed</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">cp</span>
498:           <span class="ruby-keyword kw">end</span>
499:         <span class="ruby-keyword kw">end</span>
500:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000540" class="method-detail">
        <a name="M000540"></a>

        <div class="method-heading">
          <a href="#M000540" class="method-signature">
          <span class="method-name">g_pack</span><span class="method-args">(unpacked)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Reverse operation of <a href="UTF8Handler.html#M000539">g_unpack</a>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000540-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000540-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 421</span>
421:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">g_pack</span>(<span class="ruby-identifier">unpacked</span>)
422:         <span class="ruby-identifier">unpacked</span>.<span class="ruby-identifier">flatten</span>
423:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000539" class="method-detail">
        <a name="M000539"></a>

        <div class="method-heading">
          <a href="#M000539" class="method-signature">
          <span class="method-name">g_unpack</span><span class="method-args">(str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Unpack the string at grapheme boundaries instead of codepoint boundaries
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000539-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000539-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 390</span>
390:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">g_unpack</span>(<span class="ruby-identifier">str</span>)
391:         <span class="ruby-identifier">codepoints</span> = <span class="ruby-identifier">u_unpack</span>(<span class="ruby-identifier">str</span>)
392:         <span class="ruby-identifier">unpacked</span> = []
393:         <span class="ruby-identifier">pos</span> = <span class="ruby-value">0</span>
394:         <span class="ruby-identifier">marker</span> = <span class="ruby-value">0</span>
395:         <span class="ruby-identifier">eoc</span> = <span class="ruby-identifier">codepoints</span>.<span class="ruby-identifier">length</span>
396:         <span class="ruby-keyword kw">while</span>(<span class="ruby-identifier">pos</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">eoc</span>)
397:           <span class="ruby-identifier">pos</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
398:           <span class="ruby-identifier">previous</span> = <span class="ruby-identifier">codepoints</span>[<span class="ruby-identifier">pos</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>]
399:           <span class="ruby-identifier">current</span> = <span class="ruby-identifier">codepoints</span>[<span class="ruby-identifier">pos</span>]
400:           <span class="ruby-keyword kw">if</span> (
401:               <span class="ruby-comment cmt"># CR X LF</span>
402:               <span class="ruby-identifier">one</span> = ( <span class="ruby-identifier">previous</span> <span class="ruby-operator">==</span> <span class="ruby-constant">UCD</span>.<span class="ruby-identifier">boundary</span>[<span class="ruby-identifier">:cr</span>] <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">current</span> <span class="ruby-operator">==</span> <span class="ruby-constant">UCD</span>.<span class="ruby-identifier">boundary</span>[<span class="ruby-identifier">:lf</span>] ) <span class="ruby-keyword kw">or</span>
403:               <span class="ruby-comment cmt"># L X (L|V|LV|LVT)</span>
404:               <span class="ruby-identifier">two</span> = ( <span class="ruby-constant">UCD</span>.<span class="ruby-identifier">boundary</span>[<span class="ruby-identifier">:l</span>] <span class="ruby-operator">===</span> <span class="ruby-identifier">previous</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">in_char_class?</span>(<span class="ruby-identifier">current</span>, [<span class="ruby-identifier">:l</span>,<span class="ruby-identifier">:v</span>,<span class="ruby-identifier">:lv</span>,<span class="ruby-identifier">:lvt</span>]) ) <span class="ruby-keyword kw">or</span>
405:               <span class="ruby-comment cmt"># (LV|V) X (V|T)</span>
406:               <span class="ruby-identifier">three</span> = ( <span class="ruby-identifier">in_char_class?</span>(<span class="ruby-identifier">previous</span>, [<span class="ruby-identifier">:lv</span>,<span class="ruby-identifier">:v</span>]) <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">in_char_class?</span>(<span class="ruby-identifier">current</span>, [<span class="ruby-identifier">:v</span>,<span class="ruby-identifier">:t</span>]) ) <span class="ruby-keyword kw">or</span>
407:               <span class="ruby-comment cmt"># (LVT|T) X (T)</span>
408:               <span class="ruby-identifier">four</span> = ( <span class="ruby-identifier">in_char_class?</span>(<span class="ruby-identifier">previous</span>, [<span class="ruby-identifier">:lvt</span>,<span class="ruby-identifier">:t</span>]) <span class="ruby-keyword kw">and</span> <span class="ruby-constant">UCD</span>.<span class="ruby-identifier">boundary</span>[<span class="ruby-identifier">:t</span>] <span class="ruby-operator">===</span> <span class="ruby-identifier">current</span> ) <span class="ruby-keyword kw">or</span>
409:               <span class="ruby-comment cmt"># X Extend</span>
410:               <span class="ruby-identifier">five</span> = (<span class="ruby-constant">UCD</span>.<span class="ruby-identifier">boundary</span>[<span class="ruby-identifier">:extend</span>] <span class="ruby-operator">===</span> <span class="ruby-identifier">current</span>)
411:             )
412:           <span class="ruby-keyword kw">else</span>
413:             <span class="ruby-identifier">unpacked</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">codepoints</span>[<span class="ruby-identifier">marker</span><span class="ruby-operator">..</span><span class="ruby-identifier">pos</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>]
414:             <span class="ruby-identifier">marker</span> = <span class="ruby-identifier">pos</span>
415:           <span class="ruby-keyword kw">end</span>
416:         <span class="ruby-keyword kw">end</span> 
417:         <span class="ruby-identifier">unpacked</span>
418:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000537" class="method-detail">
        <a name="M000537"></a>

        <div class="method-heading">
          <a href="#M000537" class="method-signature">
          <span class="method-name">in_char_class?</span><span class="method-args">(codepoint, classes)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Detect whether the codepoint is in a certain character class. Primarily
used by the grapheme cluster support.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000537-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000537-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 376</span>
376:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">in_char_class?</span>(<span class="ruby-identifier">codepoint</span>, <span class="ruby-identifier">classes</span>)
377:         <span class="ruby-identifier">classes</span>.<span class="ruby-identifier">detect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-constant">UCD</span>.<span class="ruby-identifier">boundary</span>[<span class="ruby-identifier">c</span>] <span class="ruby-operator">===</span> <span class="ruby-identifier">codepoint</span> } <span class="ruby-operator">?</span> <span class="ruby-keyword kw">true</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">false</span>
378:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000541" class="method-detail">
        <a name="M000541"></a>

        <div class="method-heading">
          <a href="#M000541" class="method-signature">
          <span class="method-name">justify</span><span class="method-args">(str, integer, way, padstr=' ')</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Justifies a string in a certain way. Valid values for <tt>way</tt> are
<tt>:right</tt>, <tt>:left</tt> and <tt>:<a
href="UTF8Handler.html#M000520">center</a></tt>. Is primarily used as a
helper method by <tt><a href="UTF8Handler.html#M000518">rjust</a></tt>,
<tt><a href="UTF8Handler.html#M000519">ljust</a></tt> and <tt><a
href="UTF8Handler.html#M000520">center</a></tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000541-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000541-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 427</span>
427:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">justify</span>(<span class="ruby-identifier">str</span>, <span class="ruby-identifier">integer</span>, <span class="ruby-identifier">way</span>, <span class="ruby-identifier">padstr</span>=<span class="ruby-value str">' '</span>)
428:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;zero width padding&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">padstr</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
429:         <span class="ruby-identifier">padsize</span> = <span class="ruby-identifier">integer</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">size</span>(<span class="ruby-identifier">str</span>)
430:         <span class="ruby-identifier">padsize</span> = <span class="ruby-identifier">padsize</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">padsize</span> <span class="ruby-operator">:</span> <span class="ruby-value">0</span>
431:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">way</span>
432:         <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:right</span>
433:           <span class="ruby-identifier">str</span>.<span class="ruby-identifier">dup</span>.<span class="ruby-identifier">insert</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">padding</span>(<span class="ruby-identifier">padsize</span>, <span class="ruby-identifier">padstr</span>))
434:         <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:left</span>
435:           <span class="ruby-identifier">str</span>.<span class="ruby-identifier">dup</span>.<span class="ruby-identifier">insert</span>(<span class="ruby-value">-1</span>, <span class="ruby-identifier">padding</span>(<span class="ruby-identifier">padsize</span>, <span class="ruby-identifier">padstr</span>))
436:         <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:center</span>
437:           <span class="ruby-identifier">lpad</span> = <span class="ruby-identifier">padding</span>((<span class="ruby-identifier">padsize</span> <span class="ruby-operator">/</span> <span class="ruby-value">2.0</span>).<span class="ruby-identifier">floor</span>, <span class="ruby-identifier">padstr</span>)
438:           <span class="ruby-identifier">rpad</span> = <span class="ruby-identifier">padding</span>((<span class="ruby-identifier">padsize</span> <span class="ruby-operator">/</span> <span class="ruby-value">2.0</span>).<span class="ruby-identifier">ceil</span>, <span class="ruby-identifier">padstr</span>)
439:           <span class="ruby-identifier">str</span>.<span class="ruby-identifier">dup</span>.<span class="ruby-identifier">insert</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">lpad</span>).<span class="ruby-identifier">insert</span>(<span class="ruby-value">-1</span>, <span class="ruby-identifier">rpad</span>)
440:         <span class="ruby-keyword kw">end</span>
441:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000542" class="method-detail">
        <a name="M000542"></a>

        <div class="method-heading">
          <a href="#M000542" class="method-signature">
          <span class="method-name">padding</span><span class="method-args">(padsize, padstr=' ')</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Generates a <a href="UTF8Handler.html#M000542">padding</a> string of a
certain <a href="UTF8Handler.html#M000524">size</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000542-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000542-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 444</span>
444:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">padding</span>(<span class="ruby-identifier">padsize</span>, <span class="ruby-identifier">padstr</span>=<span class="ruby-value str">' '</span>)
445:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">padsize</span> <span class="ruby-operator">!=</span> <span class="ruby-value">0</span>
446:           <span class="ruby-identifier">slice</span>(<span class="ruby-identifier">padstr</span> <span class="ruby-operator">*</span> ((<span class="ruby-identifier">padsize</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">size</span>(<span class="ruby-identifier">padstr</span>)) <span class="ruby-operator">+</span> <span class="ruby-value">1</span>), <span class="ruby-value">0</span>, <span class="ruby-identifier">padsize</span>)
447:         <span class="ruby-keyword kw">else</span>
448:           <span class="ruby-value str">''</span>
449:         <span class="ruby-keyword kw">end</span>
450:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000544" class="method-detail">
        <a name="M000544"></a>

        <div class="method-heading">
          <a href="#M000544" class="method-signature">
          <span class="method-name">reorder_characters</span><span class="method-args">(codepoints)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Re-order codepoints so the string becomes canonical
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000544-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000544-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 466</span>
466:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reorder_characters</span>(<span class="ruby-identifier">codepoints</span>)
467:         <span class="ruby-identifier">length</span> = <span class="ruby-identifier">codepoints</span>.<span class="ruby-identifier">length</span><span class="ruby-operator">-</span> <span class="ruby-value">1</span>
468:         <span class="ruby-identifier">pos</span> = <span class="ruby-value">0</span>
469:         <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">pos</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">length</span> <span class="ruby-keyword kw">do</span>
470:           <span class="ruby-identifier">cp1</span>, <span class="ruby-identifier">cp2</span> = <span class="ruby-constant">UCD</span>[<span class="ruby-identifier">codepoints</span>[<span class="ruby-identifier">pos</span>]], <span class="ruby-constant">UCD</span>[<span class="ruby-identifier">codepoints</span>[<span class="ruby-identifier">pos</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>]]
471:           <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">cp1</span>.<span class="ruby-identifier">combining_class</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">cp2</span>.<span class="ruby-identifier">combining_class</span>) <span class="ruby-operator">&amp;&amp;</span> (<span class="ruby-identifier">cp2</span>.<span class="ruby-identifier">combining_class</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>)
472:             <span class="ruby-identifier">codepoints</span>[<span class="ruby-identifier">pos</span><span class="ruby-operator">..</span><span class="ruby-identifier">pos</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>] = <span class="ruby-identifier">cp2</span>.<span class="ruby-identifier">code</span>, <span class="ruby-identifier">cp1</span>.<span class="ruby-identifier">code</span>
473:             <span class="ruby-identifier">pos</span> <span class="ruby-operator">+=</span> (<span class="ruby-identifier">pos</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">?</span> <span class="ruby-value">-1</span> <span class="ruby-operator">:</span> <span class="ruby-value">1</span>)
474:           <span class="ruby-keyword kw">else</span>
475:             <span class="ruby-identifier">pos</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
476:           <span class="ruby-keyword kw">end</span>
477:         <span class="ruby-keyword kw">end</span>
478:         <span class="ruby-identifier">codepoints</span>
479:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000543" class="method-detail">
        <a name="M000543"></a>

        <div class="method-heading">
          <a href="#M000543" class="method-signature">
          <span class="method-name">to_case</span><span class="method-args">(way, str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Convert characters to a different case
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000543-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000543-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 453</span>
453:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_case</span>(<span class="ruby-identifier">way</span>, <span class="ruby-identifier">str</span>)
454:         <span class="ruby-identifier">u_unpack</span>(<span class="ruby-identifier">str</span>).<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">codepoint</span><span class="ruby-operator">|</span>
455:           <span class="ruby-identifier">cp</span> = <span class="ruby-constant">UCD</span>[<span class="ruby-identifier">codepoint</span>] 
456:           <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">cp</span>.<span class="ruby-identifier">nil?</span>
457:             <span class="ruby-identifier">ncp</span> = <span class="ruby-identifier">cp</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">way</span>)
458:             <span class="ruby-identifier">ncp</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">ncp</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">codepoint</span>
459:           <span class="ruby-keyword kw">else</span>
460:             <span class="ruby-identifier">codepoint</span>
461:           <span class="ruby-keyword kw">end</span>
462:         <span class="ruby-keyword kw">end</span>.<span class="ruby-identifier">pack</span>(<span class="ruby-value str">'U*'</span>)
463:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000538" class="method-detail">
        <a name="M000538"></a>

        <div class="method-heading">
          <a href="#M000538" class="method-signature">
          <span class="method-name">u_unpack</span><span class="method-args">(str)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Unpack the string at codepoints boundaries
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000538-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000538-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 381</span>
381:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">u_unpack</span>(<span class="ruby-identifier">str</span>)
382:         <span class="ruby-keyword kw">begin</span>
383:           <span class="ruby-identifier">str</span>.<span class="ruby-identifier">unpack</span> <span class="ruby-value str">'U*'</span>
384:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ArgumentError</span>
385:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">EncodingError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">'malformed UTF-8 character'</span>)
386:         <span class="ruby-keyword kw">end</span>
387:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>